package com.etime.perfectschool.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.perfectschool.mapper.UserMapper;
import com.etime.perfectschool.pojo.User;
import com.etime.perfectschool.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public Page<User> getMyAllSchoolNews(int id, int current, int size) {
        Page<User> page=new Page<>(current,size);
        return userMapper.getMyAllSchoolNews(id,page);
    }

    @Override
    public Page<User> getMyAllschoolActivies(int id, int current, int size) {
        Page<User> page=new Page<>(current,size);
        return userMapper.getMyAllschoolActivies(id,page);
    }

    //  判断用户名是否存在
    @Override
    public boolean getUserByName(String name) {
        User user = userMapper.getUserByName(name);
        if (user!=null){
            if (user.getRole()==1){
                return true;
            }
        }
        return false;
    }

    //  用户登录
    @Override
    public User getUser(Map<String, Object> map) {
        return userMapper.getUser(map);
    }

    //   用户注册
    @Override
    public boolean addUser(User user) {
        return userMapper.insert(user)==0?false:true;
    }

    //  通过id查看用户信息
    @Override
    public User getUserById(int id) {
        return  userMapper.selectById(id);
    }

    @Override
    public int updateUser(Map<String,Object> map) {
        return userMapper.updateUser(map);
    }
}
